package com.mutual.reins.danger.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mutual.reins.danger.entity.PrptDangerPlan;
import com.mutual.reins.danger.mapper.PrptDangerPlanMapper;
import com.mutual.reins.danger.service.IPrptDangerPlanService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author CodeGenerate
 * @since 2021-03-31
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class PrptDangerPlanServiceImpl extends ServiceImpl<PrptDangerPlanMapper, PrptDangerPlan> implements IPrptDangerPlanService {

    /**
     * 获取该对象Map（key：投保单号—危险单位号 value：List<PrptDangerPlan>）
     *
     * @param queryWrapper 查询条件
     * @return 获取该对象Map
     */
    @Override
    public Map<String, List<PrptDangerPlan>> selectPrptDangerPlanMap(QueryWrapper queryWrapper) {
        List<PrptDangerPlan> prptDangerPlanList = this.list(queryWrapper);
        Map<String,List<PrptDangerPlan>> prptDangerPlanMap = new HashMap<>(16);
        if(ObjectUtil.isNotNull(prptDangerPlanList) && !prptDangerPlanList.isEmpty()){
            for(PrptDangerPlan prptDangerPlan:prptDangerPlanList){
                if(prptDangerPlanMap.containsKey(prptDangerPlan.getProposalNo()+"-"+prptDangerPlan.getDangerNo())){
                    List<PrptDangerPlan> prptDangerPlanMapList = prptDangerPlanMap.get(prptDangerPlan.getProposalNo()+"-"+prptDangerPlan.getDangerNo());
                    prptDangerPlanMapList.add(prptDangerPlan);
                }else{
                    List<PrptDangerPlan> prptDangerPlanMapList = new ArrayList<>();
                    prptDangerPlanMapList.add(prptDangerPlan);
                    prptDangerPlanMap.put(prptDangerPlan.getProposalNo()+"-"+prptDangerPlan.getDangerNo(),prptDangerPlanMapList);
                }
            }
        }
        return prptDangerPlanMap;
    }
}
